package com.gitee.wsl.mathematics.geometry.d2.rect.ext

import com.gitee.wsl.mathematics.geometry.d2.base.Direction
import com.gitee.wsl.mathematics.geometry.d2.rect.RectangleShape2d

/**
 * Returns a copy of the [Rect2i] grown by the specified `amount` on all sides.
 */
fun<N:Number> RectangleShape2d<N, *, *>.grow(amount: N) = createWH(
    x - amount,
    y - amount,
    width + amount * 2,
    height + amount * 2
)

/**
 * Returns a copy of the [Rect2i] grown by the specified amount on each side individually.
 */
fun<N:Number> RectangleShape2d<N, *, *>.growIndividual(left: N, top: N, right: N, bottom: N) = createWH(
    x - left,
    y - top,
    width + left + right,
    height + top + bottom
)

/**
 * Returns a copy of the [Rect2i] grown by the specified [amount] on the specified [Side].
 */
fun<N:Number> RectangleShape2d<N, *, *>.growSide(side: Direction, amount: N) = growIndividual(
    if (Direction.LEFT === side) amount else zero,
    if (Direction.UP === side) amount else zero,
    if (Direction.RIGHT === side) amount else zero,
    if (Direction.DOWN === side) amount else zero
)